import { reactive, watchEffect } from 'vue';

export const useBigCategory = (props, emits) => {
  const bigCategoryData = reactive({
    data: {
      subCategoryList: [],
    },
  });

  watchEffect(() => {
    bigCategoryData.data = props.bigCategoryItem;
  });
  const uploadSuccess = subItem => {
    const bigIndex = bigCategoryData.data.subCategoryList.findIndex(item => item.categoryCode == subItem.categoryCode);
    bigCategoryData.data.subCategoryList[bigIndex] = subItem;
    emits('uploadSuccess', bigCategoryData.data);
  };
  const deleteSuccess = subItem => {
    const bigIndex = bigCategoryData.data.subCategoryList.findIndex(item => item.categoryCode == subItem.categoryCode);
    bigCategoryData.data.subCategoryList[bigIndex] = subItem;
    emits('deleteSuccess', bigCategoryData.data);
  };
  return {
    bigCategoryData,
    uploadSuccess,
    deleteSuccess,
  };
};
